Repository navigation
Conversation
Undo letterboxing using its recorded ratio and padding, then scale x and y independently back to the original camera image. Preserve inference pixels and final clipping. Add CPU regression cases for square, non-square, padded, edge and empty detections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The detector first resizes the image to
(image_size, int(image_size * 0.7)), then applies letterboxing. Its previous call toscale_coords(..., orig_shape)assumed an aspect-preserving resize directly from the original image. That inverse does not match the actual preprocessing, so boxes can shift sideways or collapse at the image boundary before being passed to SAM.For a 640 × 640 observation and the default image size, preprocessing produces a 640 × 448 image with no letterbox padding. A recorded chair detection
[499.5, 218.625, 554.5, 288.0]was restored to[576, 312, 639, 411]; the correct result is[500, 312, 554, 411].This change restores coordinates in two stages: undo letterboxing with its returned ratio/padding, then undo the preceding resize with independent width/height factors. Existing rounding, clipping and filtering remain in place. Model input pixels, weights, confidence/NMS settings and navigation logic are unchanged.
Validation:
detect()preprocessing and restoration with mocked inference output/device transfer. They cover actual failing detections, image-edge collapse, landscape/portrait/odd-sized images, letterbox padding, clipping and empty output. The original implementation fails 7/9; the fix passes 9/9.python -m unittest discover -s tests -p 'test_yolov7_coordinates.py' -v.Overall progress remains 2/9 planned targets and 0/3 complete sequences; this small slice does not demonstrate improved navigation success. Later targets can start from different poses after the preceding target's trajectory changes.
A full mapper replay of episode 1 isolates the geometric improvement: at observation index 102, the corrected SAM prompt yields 2663 chair pixels out of a 2692-pixel mask (98.9%), compared with 0 chair pixels in the original 2134-pixel mask. It still fails because the new candidate's adjusted similarity (1.07924) is below the existing replacement threshold (1.10323), so the old candidate is retained and the distance-based stop fires. Candidate replacement and stopping are separate concerns and are unchanged in this PR.
Only the detector coordinate restoration and its regression tests are included.